<template>
  <div id="PerProcess">
    <div class="ge" v-show="!spinner"></div>
    <div class="spinner" v-show="spinner">
      <div class="bounce1"></div>
      <div class="bounce2"></div>
      <div class="bounce3"></div>
    </div>      
    <div class="contentTwo-head" v-for="(item,i) in Content" :key="i">
        <div>
            <div class="contentTwo-left"><span></span></div>
            <div class="contentTwo-right">               
                <span>{{item.APPLY_STATE  | dateApplyState}}</span>
            </div>
            <br />
        </div>
        <div>
            <div class="contentTwo-name"><span class="contentTwo-text">{{item.POWERAPPLY_NAME | dateEmpty}}</span></div>
            <br />
        </div>         
        <div>
            <div class="lie-left">填写人员：</div>
            <div class="lie_right">{{item.OPERATE_USERNAME | dateEmpty}}</div>
            <br />
        </div>					
        <div>
            <div class="lie-left">填写时间：</div>
            <div class="lie_right">{{item.OPERATE_DATE | dateEmpty}}</div>
            <br />
        </div>
        <div>
            <div class="lie-left">申请详情：</div>
            <br />
            <div class="lie_rightP">
              <div v-for="(jur,j) in Jurisdiction" :key="j">
                <p>{{j+1}}、{{jur.PROCESS_NAME | dateEmpty}}</p>     
                <div class="jurDiv" v-for="(jurx,k) in jurXq[j]" :key="k" @click="jurDivPShow(j,k)">
                  <span class="jurDivL">{{jurx.name}}</span>
                  <span class="jurDivR" :id="j+'s1'+k" v-show="jurImgN[j]"><img src="../../static/img/yxiang.png" width="70%"></span>
                  <span class="jurDivR none" :id="j+'s2'+k" v-show="jurImgN[j]"><img src="../../static/img/xxiang.png" width="70%"></span>
                  <br />
                  <div class="jurDivP" :id="j+'s'+k" v-show="jurImgN[j]">
                    {{jurx.personnel}}
                  </div>
                </div>    
              </div>
            </div>
            <br />
        </div>   
        <div v-show="Toexamine" class="to-examine" @click="menuImg()">
            <img src="../../static/img/BusinessSub/ddsh.png" width="20%" /> 
            审核
        </div>              
        <div class="process" v-for="(item,i) in process" :key="i" v-show="proshow[i]">
          <img src="../../static/img/BusinessSub/sjq.png" width="6%" class="sjq" />
          <img src="../../static/img/BusinessSub/rl.png" width="4.5%" class="rl" />
          <div class="sjxian" v-show="sjshow[i]"></div>
          {{item.OPERATE_DATE | dateEmpty}}
          <p>【{{item.APPLY_STATE | datePerType}}】{{item.APPLY_NAME | dateEmpty}}：{{item.APPLY_REASON | dateEmpty}}；</p>
          <hr />
        </div>    
        <div class="xial" v-show="xial" @click="clickProshow()">
          <img src="../../static/img/xxiang.png" width="5%" />
        </div>       
        <div class="xial" v-show="shangl" @click="clickProshowS()">
          <img src="../../static/img/sxiang.png" width="5%" />
        </div> 
        <br />       
    </div>    
    <mt-popup v-model="PopupVisible3" position="">
        <div class="opinion">
            <p class="opinion-title">意见</p>
            <mt-field placeholder="" type="textarea" rows="4" class="PURCHASE-DESC" v-model="PURCHASEDESC" @input="desTextarea"></mt-field>
            <hr class="opinion-hr" />
        </div>
        <button class="buttton1" :class="disabledClass" v-bind:disabled="disabled" @click="examine()">通过</button>
        <button class="buttton2" :class="disabledClass" v-bind:disabled="disabled" @click="fallback()">驳回</button>
        <br />
    </mt-popup>   
    <!-- 审核动画 -->
    <div class="trialani" v-show="trialani">
      <img :src="trialImg" alt="" width="45%">
      <p v-text="trialtext"></p>
    </div>
    <!-- end -->           
  </div>
</template>

<script>
import store from "@/store/store.js";
import trialImg from "../../static/img/BusinessSub/33.png";
import trialImgT from "../../static/img/BusinessSub/complete.gif";
import trialImgF from "../../static/img/BusinessSub/completeF.gif";
import jurImgY from "../../static/img/yxiang.png";
import jurImgX from "../../static/img/xxiang.png";
import { Indicator } from "mint-ui";
export default {
  name: "PerProcess",
  data() {
    return {
      Url:
        "http://mall.eshangtech.com:8010/MobileServicePlatform/Handler/handler_ajax.ashx?",
      Content: [],
      spinner: true,
      process: [],
      processLength: "",
      Toexamine: "",
      PopupVisible3: false,
      PURCHASEDESC: "",
      disabled: true,
      disabledClass: "disabled",
      trialani: false,
      trialtext: "",
      trialImg: "../../static/img/BusinessSub/33.png",
      trialImgT: "../../static/img/BusinessSub/complete.gif",
      trialImgF: "../../static/img/BusinessSub/completeF.gif",
      Jurisdiction: [],
      jurstr: [],
      jurImgN: [],
      jurImgY: "../../static/img/yxiang.png",
      jurImgX: "../../static/img/xxiang.png",
      jurXq: [],
      sjshow: [],
      proshow: [],
      xial: false,
      shangl: false
    };
  },
  methods: {
    menuImg: function() {
      this.PURCHASEDESC = "";
      this.PopupVisible3 = !this.PopupVisible3;
    },
    // 意见非空验证
    desTextarea: function() {
      if (this.PURCHASEDESC != "") {
        this.disabled = false;
        this.disabledClass = "";
      } else {
        this.disabled = true;
        this.disabledClass = "disabled";
      }
    },
    // 审核
    examine: function() {
      let POWERAPPLY_ID = this.$route.params.id; //需要审批的申请单内码
      let APPLY_REASON = this.PURCHASEDESC; //审批意见
      this.PopupVisible3 = false;
      Indicator.open();
      this.$http
        .get(
          this.Url +
            "action_type=UpdatePermissionApproval&action_data=[{POWERAPPLY_ID:" +
            POWERAPPLY_ID +
            ",APPLY_ID:" +
            store.state.wxid +
            ",APPLY_STATE:0,APPLY_REASON:'" +
            APPLY_REASON +
            "'}]"
        )
        .then(response => {
          Indicator.close();
          // success callback
          // console.log(response.data);
          if (response.data == "1") {
            this.trialani = true;
            this.trialImg = trialImgT;
            this.trialtext = "审核通过";
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
              this.getJurisdiction();
            }, 2000);
          } else {
            this.trialani = true;
            this.trialImg = trialImgF;
            this.trialtext = response.data;
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
              this.getJurisdiction();
            }, 3000);
          }
        })
        .catch(error => {
          // console.log(error);
        });
    },
    // 回退
    fallback: function() {
      let POWERAPPLY_ID = this.$route.params.id; //需要审批的申请单内码
      let APPLY_REASON = this.PURCHASEDESC; //审批意见
      this.PopupVisible3 = false;
      Indicator.open();
      this.$http
        .get(
          this.Url +
            "action_type=UpdatePermissionApproval&action_data=[{POWERAPPLY_ID:" +
            POWERAPPLY_ID +
            ",APPLY_ID:" +
            store.state.wxid +
            ",APPLY_STATE:1,APPLY_REASON:'" +
            APPLY_REASON +
            "'}]"
        )
        .then(response => {
          Indicator.close();
          // success callback
          // console.log(response.data);
          if (response.data == "1") {
            this.trialani = true;
            this.trialImg = trialImgT;
            this.trialtext = "驳回通过";
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
              this.getJurisdiction();
            }, 2000);
          } else {
            this.trialani = true;
            this.trialImg = trialImgF;
            this.trialtext = response.data;
            setTimeout(() => {
              this.trialani = false;
              this.trialImg = trialImg;
              this.getJurisdiction();
            }, 3000);
          }
        })
        .catch(error => {
          // console.log(error);
        });
    },
    //加载数据
    getJurisdiction: function() {
      this.$http
        .get(
          this.Url +
            "action_type=GetApplyList&RTWECHATPUSH_ID=" +
            store.state.wxid +
            "&APPLY_ID=" +
            this.$route.params.id
        )
        .then(response => {
          // success callback
          this.spinner = false;
          this.Content = response.data.GetApplyList;

          this.$http
            .get(
              this.Url +
                "action_type=GetApplyContent&Apply_ID=" +
                this.$route.params.id
            )
            .then(response => {
              // success callback
              // console.log(response.data.GetApplyContent);
              this.Jurisdiction = response.data.GetApplyContent;
              let i = 0;
              response.data.GetApplyContent.forEach(val => {
                if (val.APPLY_NAME.indexOf(";") > 0) {
                  this.jurImgN[i] = true;
                  let jsurs = val.APPLY_NAME.split(";");
                  let jusArr = new Array();
                  for (let j = 0; j < jsurs.length; j++) {
                    let qx = jsurs[j].split(":");
                    let Obj = {};
                    Obj.name = qx[0];
                    Obj.personnel = qx[1];
                    jusArr.push(Obj);
                  }
                  this.jurXq[i] = jusArr;
                } else {
                  this.jurImgN[i] = false;
                  let Obj = {};
                  let jusArr = new Array();
                  Obj.name = val.APPLY_NAME;
                  Obj.personnel = "";
                  jusArr.push(Obj);
                  this.jurXq[i] = jusArr;
                }
                i++;
              });
            })
            .catch(error => {
              // console.log(error);
            });

          if (
            response.data.GetApplyList[0].APPLY_STATE == "9999" ||
            response.data.GetApplyList[0].ISSYSTEM == "2" ||
            response.data.GetApplyList[0].ISVISIBLE == "0"
          ) {
            this.Toexamine = false;
          } else {
            this.Toexamine = true;
          }
          this.getPerProcess();
        })
        .catch(error => {
          // console.log(error);
        });
    },
    // 加载审核流程
    getPerProcess: function() {
      this.$http
        .get(
          this.Url +
            "action_type=GetApplyProcess&Apply_ID=" +
            this.$route.params.id
        )
        .then(response => {
          // success callback
          this.process = response.data.GetApplyProcess;
          this.processLength = response.data.GetApplyProcess.length;
          if (this.processLength > 3) {
            this.xial = true;
          }
          for (let i = 0; i < this.processLength; i++) {
            if (i == this.processLength - 1 || i == 2) {
              this.sjshow[i] = false;
            } else {
              this.sjshow[i] = true;
            }
            if (i < 3) {
              this.proshow[i] = true;
            } else {
              this.proshow[i] = false;
            }
          }
        })
        .catch(error => {
          // console.log(error);
        });
    },
    clickProshow: function() {
      for (let i = 0; i < this.processLength; i++) {
        this.proshow[i] = true;
      }
      this.xial = false;
      this.shangl = true;
      this.sjshow[2] = true;
    },
    clickProshowS: function() {
      for (let i = 0; i < this.processLength; i++) {
        if (i > 2) {
          this.proshow[i] = false;
        }
      }
      this.xial = true;
      this.shangl = false;
      this.sjshow[2] = false;
    },
    jurDivPShow: function(j, k) {
      let jurDivRimg1 = document.getElementById(j + "s1" + k).style.display;
      let jurDivRimg2 = document.getElementById(j + "s2" + k).style.display;
      if (jurDivRimg1 != "none" || jurDivRimg2 != "none") {
        let jurdisplay = document.getElementById(j + "s" + k).style.display;
        if (jurdisplay == "block") {
          document.getElementById(j + "s" + k).style.display = "none";
          document.getElementById(j + "s1" + k).style.display = "block";
          document.getElementById(j + "s2" + k).style.display = "none";
        } else {
          document.getElementById(j + "s" + k).style.display = "block";
          document.getElementById(j + "s1" + k).style.display = "none";
          document.getElementById(j + "s2" + k).style.display = "block";
        }
      }
    }
  },
  created() {
    this.getJurisdiction();
    // console.log(this.$route.params.id);
  }
};
</script>

<style scoped>
.ge {
  padding: 2.5rem 0 0 0;
}
.contentTwo-head {
  width: 100%;
  margin: 0.5rem 0 0 0;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  background-color: #fff;
  position: relative;
}
.contentTwo-left {
  width: 60%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.contentTwo-right {
  width: 40%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
  text-align: right;
  padding-right: 1rem;
}
.contentTwo-name {
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.contentTwo-text {
  font-size: 20px;
  color: #ec9061;
}
.lie-left {
  width: 18%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.lie_right {
  width: 82%;
  float: left;
  height: 1.5rem;
  line-height: 1.5rem;
}
.lie_rightP {
  width: 100%;
  float: left;
  line-height: 1.5rem;
}
.process {
  padding: 0.5rem;
  margin-bottom: 0.2rem;
  margin-left: 2rem;
  position: relative;
}
.sjq {
  position: absolute;
  top: 0.35rem;
  left: -2.1rem;
}
.rl {
  position: absolute;
  top: 0.45rem;
  left: -0.5rem;
}
.sjxian {
  width: 1px;
  height: 2.65rem;
  float: left;
  background: #fc9153;
  position: absolute;
  top: 1rem;
  left: -1.65rem;
}
.xial {
  text-align: center;
}
.to-examine {
  width: 15%;
  height: 1.5rem;
  line-height: 1.5rem;
  float: right;
}
.opinion {
  width: 15rem;
  padding: 15px 10px;
  text-align: center;
  border-bottom: 1px solid #dedede;
  border-radius: 2px 2px 0 0;
}
.opinion-title {
  font-size: 16px;
}
.PURCHASE-DESC {
  width: 100%;
  border: none #fff;
  background: transparent;
  outline: none;
  color: #000;
}
.opinion-hr {
  width: 100%;
  color: black;
  margin: 0.35rem auto;
}
.buttton1 {
  width: 50%;
  background-color: #4c4b5b;
  border: none;
  height: 2.25rem;
  color: #fff;
  float: left;
}
.buttton2 {
  width: 50%;
  background-color: #ec9061;
  border: none;
  height: 2.25rem;
  color: #fff;
  float: left;
}
.disabled {
  opacity: 0.3;
}
.trialani {
  width: 10rem;
  height: 6rem;
  box-shadow: 0px 1px 8px 0.2px #e2e2e2;
  text-align: center;
  background-color: #fff;
  position: fixed;
  top: 42%;
  left: 50%;
  -webkit-transform: translate3d(-50%, -50%, 0);
  -moz-transform: translate3d(-50%, -50%, 0);
  -o-transform: translate3d(-50%, -50%, 0);
  -ms-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
}
.jurDiv {
  width: 100%;
  min-height: 2rem;
  line-height: 2rem;
  padding: 0 1rem 0 1rem;
  box-shadow: 0px 1px 8px 0.5px #e2e2e2;
  margin-bottom: 0.5rem;
}
.jurDivL {
  float: left;
}
.jurDivR {
  float: right;
}
.jurDivP {
  min-height: 1.3rem;
  line-height: 1rem;
  display: none;
}
.none {
  display: none;
}
</style>

